package com.jack.controller;


import com.jack.pojo.Clazz;
import com.jack.queryParam.ClazzQueryParam;
import com.jack.result.PageResult;
import com.jack.result.Result;
import com.jack.service.ClazzService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/clazzs")
public class ClazzController {

    private static final Logger log = LoggerFactory.getLogger(ClazzController.class);
    @Autowired
    private ClazzService clazzService;


    /**
     *  添加班级
     * @param clazz
     * @return
     */
    @PostMapping
    public Result addClazz(@RequestBody Clazz clazz) {
        clazzService.addClazz(clazz);
        return Result.success();
    }

    /**
     * 删除班级
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public Result deleteClazz(@PathVariable Integer id) {
        clazzService.deleteClazz(id);
        return Result.success();
    }

    /**
     * 修改班级
     * @param clazz
     * @return
     */
    @PutMapping
    public Result updateClazz(@RequestBody Clazz clazz) {
        log.info("修改班级：{}", clazz);
        clazzService.updateClazz(clazz);
        return Result.success();
    }


    /**
     * 查询所有班级
     * @return
     */
    @GetMapping("/list")
    public Result getClazzsList() {
        List<Clazz> clazzList = clazzService.getClazzsList();
        return Result.success(clazzList);
    }

    /**
     * 分页查询班级
     * @return
     */
    @GetMapping
    public Result pageClazzs(ClazzQueryParam clazzQueryParam){
        PageResult<Clazz> pageClazzs = clazzService.pageClazzs(clazzQueryParam);
        return Result.success(pageClazzs);
    }

    /**
     * 根据id查询班级
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result getClazzById(@PathVariable Integer id) {
        Clazz clazz = clazzService.getClazzById(id);
        return Result.success(clazz);
    }

}
